-
Notifications
You must be signed in to change notification settings - Fork 243
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Config: Make preset config aware of cpu/memory #3636
Conversation
if _, err := c.Unset(key); err != nil { | ||
return "", err | ||
} | ||
return "", nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think we should print a message letting the user know the config is restored to its default, since we won't see the config option in config view
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@anjannath Currently also we are not seeing the default configs as part of config view
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
right, do you prefer to keep it that way, or show a message saying Configuration property '%s' restored to default value '%s'
(since you are in the file ;) )
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@anjannath better to keep it that way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also think we need to inform the user that we changed their configuration settings. I'll add that.
@@ -121,7 +121,7 @@ func TestViperConfigLoadDefaultValue(t *testing.T) { | |||
|
|||
bin, err := os.ReadFile(configFile) | |||
assert.NoError(t, err) | |||
assert.JSONEq(t, `{"cpus":4}`, string(bin)) | |||
assert.JSONEq(t, `{}`, string(bin)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe also add a comment here, // default values are not written to config file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Started with: {
"consent-telemetry": "yes",
"cpus": 2,
"preset": "openshift"
} PS> crc config set cpus 4 cleared the default: {
"consent-telemetry": "yes",
"preset": "openshift"
} Note: the default preset remains (?) PS> crc config set preset microshift changed the preset: {
"consent-telemetry": "yes",
"preset": "microshift"
} PS> crc config set cpus 1
PS> crc config set cpus 2 does not add the value (as matches default) PS> crc config set cpus 2 {
"consent-telemetry": "yes",
"cpus": 3,
"preset": "microshift"
} Now changing to OpenShift again: PS> crc config set preset openshift {
"consent-telemetry": "yes"
} SO this looks good... though here the default preset was cleared. Earlier it didn't. |
} | ||
} | ||
cpu := c.Get(CPUs) | ||
if err := validation.ValidateCPUs(cpu.AsInt(), preset); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't we also use disk-size? This is now identical, but would suggest to create an issue to follow-up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree to add the 'default values aren't stored' in the test
This PR make sure that if user try to set a default value for a config property then it just unset that property and default value is used. It will also allow not to have default value in the viper config file. Also add `UpdateDefaults` to set and get config handler so API can also make use of it. Without this Patch ``` $ crc config set preset microshift $ crc config set cpus 2 $ crc config set preset openshift $ cat ~/.crc/crc.json { "cpus": 2, "preset": "openshift" } ``` After this patch `~/.crc/crc.json` going to be empty and openshift preset is going to use default `cpus` as `4`.
Preset property is bound with cpu/memory/bundle and have default values for it but our `set` function doesn't have map around those settings and a user can do following without any error message. ``` $ crc config set preset microshift $ crc config set cpus 2 $ crc config set preset openshift ``` and when user try to perform `crc start` then error message shown. With this PR we are making the set function bit self aware of the preset and it's bound properties (cpu/memory) and make sure if those property doesn't validated for the preset then unset those so default values going to take over. with this PR following now works as expected. ``` $ curl -X POST -d '{"properties":{"preset": "microshift"}}' --unix-socket ~/.crc/crc-http.sock http:/c/api/config {"Properties":["preset"]} $ curl -X POST -d '{"properties":{"cpus": "3"}}' --unix-socket ~/.crc/crc-http.sock http:/c/api/config {"Properties":["cpus"]} $ curl -X POST -d '{"properties":{"preset": "openshift"}}' --unix-socket ~/.crc/crc-http.sock http:/c/api/config {"Properties":["preset"]} $ curl -X GET --unix-socket ~/.crc/crc-http.sock http:/c/api/config | jq . % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 894 100 894 0 0 56924 0 --:--:-- --:--:-- --:--:-- 59600 { "Configs": { "bundle": "/Users/prkumar/.crc/cache/crc_vfkit_4.12.13_arm64.crcbundle", "consent-telemetry": "no", "cpus": 4, "disable-update-check": true, "disk-size": 31, "enable-cluster-monitoring": false, "enable-experimental-features": false, "enable-shared-dirs": true, "host-network-access": false, "http-proxy": "", "https-proxy": "", "ingress-http-port": 80, "ingress-https-port": 443, "kubeadmin-password": "", "memory": 9216, [...] ```
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: anjannath, gbraad The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
@praveenkumar: The following test failed, say
Full PR test history. Your PR dashboard. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here. |
Found this reference to some interesting historical fact: |
Will need some follow-up work #3652 |
Preset property is bound with cpu/memory/bundle and have default
values for it but our
set
function doesn't have map around thosesettings and a user can do following without any error message.
and when user try to perform
crc start
then error message shown.With this PR we are making the set function bit self aware of the
preset and it's bound properties (cpu/memory) and make sure if those
property doesn't validated for the preset then unset those so default
values going to take over.
with this PR following now works as expected.